package sg.techstudio.suntec.formatter;

import java.text.ParseException;
import java.util.Locale;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.Formatter;
import org.springframework.stereotype.Component;

import sg.techstudio.suntec.dao.RoleDao;
import sg.techstudio.suntec.object.RoleObj;

@Component("roleFormatter")
public class RoleFormatter implements Formatter<RoleObj> {
	private static final Log log = LogFactory.getLog(RoleFormatter.class);
	
	@Autowired
	private RoleDao roleDao;

	@Override
	public String print(RoleObj role, Locale locale) {
		log.debug("print() entry :"+role.getId());
		return role.getId()+"";
//		return role.getName();
	}

	@Override
	public RoleObj parse(String roleId, Locale arg1) throws ParseException {
		log.debug("parse() entry :"+roleId);
		return roleDao.getRole(roleId);
	}
}
